# 选课

import random

import requests
import json
import time
from concurrent.futures import ThreadPoolExecutor

cookies = {
    'JSESSIONID': '8D623456E4E8014CFC4B27EE4911AE8E',
    'route': 'ea0904e1f60731f45f8ffa63eae37fca',
}

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
    'Origin': 'http://jwgl.nwu.edu.cn',
    'Referer': 'https://jwgl.nwu.edu.cn/jwglxt/xsxk/zzxkyzbjk_xkBcZyZzxkYzb.html?gnmkdm=N253512&su=2022117321',
    'User-Agent': 'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.188 Safari/537.36 CrKey/1.54.250320 Edg/120.0.0.0',
    'X-Requested-With': 'XMLHttpRequest',
}

params = {
    'gnmkdm': 'N253512',
    'su': '2022117321',
}

# def task():
data = {
    "jxb_ids": "5ce6e9f70a3824e08475ab0163275cc057b9d60d039597f3f2e1a5fdcb20c48cef65a9a4342a973a3ca52cffaa1dba2537a69e08102fc6f7d405d3478a8520ab6acdf214839ec04bc1f0dd24bc70545bbb91339c2cbed93912fd86ac5cb97e9f7be93681201976fb67f52853eac0df57e70e70f2bab8fe3cdebd39b99dedacd3",
    "kch_id": "984911AA2144C91CE055000000000001",
    "qz": "0",

    # "xkkz_id": "984911AA2144C91CE055000000000001",
    # "rwlx": "1",
    # "rlkz": "0",
    # "rlzlkz": "1",
    # "sxbj": "1",
    # "xxkbj": "0",
    # "cxbj": "0",
    # "njdm_id": "2022",
    # "zyh_id": "1805",
    # "kklxdm": "01",
    # "xklc": "2",
    # "xkxnm": "2023",
    # "xkxqm": "12"
}

# while True:
response = requests.post(
    'https://jwgl.nwu.edu.cn/jwglxt/xsxk/zzxkyzbjk_xkBcZyZzxkYzb.html',
    params=params,
    cookies=cookies,
    headers=headers,
    data=data,
    # verify=False,
)
print(response.text)
    # res = json.loads(response.text)
    # flag = res['flag']
    # localtime = time.asctime(time.localtime(time.time()))
    # if flag == "-1":
    #     print(localtime, "人满，暂时无法选课")
    # if flag == "0":
    #     print(localtime, "失败")
    # if flag == "1":
    #     print(localtime, "选课成功！")
    #     break

    # time.sleep(3 * random.random())

# def run():
#     ke = [["25e85bafe8b94fccab261e1e04859a661f82ea497b70ee64b94f16c3ffd2bf8ed89090f5ddbf862f59ef8413448c3614c0d415d1983b54b831c50c9fbd9f4e652b9536a036b8bcc9fe49c55c8638c0bd0138b059d4a891a95c2948a548d210772c161a15af14482cade789d9f2740fbd25253b01b272f6058158d7c2c9fdf218","B50E188994BDCDEDE055000000000001"]]
#     with ThreadPoolExecutor(5) as t:
#         for k in ke:
#             jxb_ids = k[0]
#             kch_id = k[1]
#             t.submit(task,jxb_ids,kch_id)
